# PHP 5 Operators

« Previous
Next Chapter »

## PHP Operators

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators

## PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

Operator | Name | Example | Result | Show it
--- | --- | --- | --- | ---
+ | Addition | $x + $y | Sum of $x and $y | Show it »
- | Subtraction | $x - $y | Difference of $x and $y | Show it »
* | Multiplication | $x * $y | Product of $x and $y | Show it »
/ | Division | $x / $y | Quotient of $x and $y | Show it »
% | Modulus | $x % $y | Remainder of $x divided by $y | Show it »
** | Exponentiation | $x ** $y | Result of raising $x to the $y'th power (Introduced in PHP 5.6) |

## PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

Assignment | Same as... | Description | Show it
--- | --- | --- | ---
x = y | x = y | The left operand gets set to the value of the expression on the right | Show it »
x += y | x = x + y | Addition | Show it »
x -= y | x = x - y | Subtraction | Show it »
x *= y | x = x * y | Multiplication | Show it »
x /= y | x = x / y | Division | Show it »
x %= y | x = x % y | Modulus | Show it »

## PHP Comparison Operators

The PHP comparison operators are used to compare two values (number or string):

Operator | Name | Example | Result | Show it
--- | --- | --- | --- | ---
== | Equal | $x == $y | Returns true if $x is equal to $y | Show it »
=== | Identical | $x === $y | Returns true if $x is equal to $y, and they are of the same type | Show it »
!= | Not equal | $x != $y | Returns true if $x is not equal to $y | Show it »
<> | Not equal | $x <> $y | Returns true if $x is not equal to $y | Show it »
!== | Not identical | $x !== $y | Returns true if $x is not equal to $y, or they are not of the same type | Show it »
> | Greater than | $x > $y | Returns true if $x is greater than $y | Show it »
< | Less than | $x < $y | Returns true if $x is less than $y | Show it »
>= | Greater than or equal to | $x >= $y | Returns true if $x is greater than or equal to $y | Show it »
<= | Less than or equal to | $x <= $y | Returns true if $x is less than or equal to $y | Show it »

## PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value.

The PHP decrement operators are used to decrement a variable's value.

Operator | Name | Description | Show it
--- | --- | --- | ---
++$x | Pre-increment | Increments $x by one, then returns $x | Show it »
$x++ | Post-increment | Returns $x, then increments $x by one | Show it »
--$x | Pre-decrement | Decrements $x by one, then returns $x | Show it »
$x-- | Post-decrement | Returns $x, then decrements $x by one | Show it »

## PHP Logical Operators

The PHP logical operators are used to combine conditional statements.

Operator | Name | Example | Result | Show it
--- | --- | --- | --- | ---
and | And | $x and $y | True if both $x and $y are true | Show it »
or | Or | $x or $y | True if either $x or $y is true | Show it »
xor | Xor | $x xor $y | True if either $x or $y is true, but not both | Show it »
&& | And | $x && $y | True if both $x and $y are true | Show it »
|| | Or | $x || $y | True if either $x or $y is true | Show it »
! | Not | !$x | True if $x is not true | Show it »

## PHP String Operators

PHP has two operators that are specially designed for strings.

Operator | Name | Example | Result | Show it
--- | --- | --- | --- | ---
. | Concatenation | $txt1 . $txt2 | Concatenation of $txt1 and $txt2 | Show it »
.= | Concatenation assignment | $txt1 .= $txt2 | Appends $txt2 to $txt1 | Show it »

## PHP Array Operators

The PHP array operators are used to compare arrays.

Operator | Name | Example | Result | Show it
--- | --- | --- | --- | ---
+ | Union | $x + $y | Union of $x and $y | Show it »
== | Equality | $x == $y | Returns true if $x and $y have the same key/value pairs | Show it »
=== | Identity | $x === $y | Returns true if $x and $y have the same key/value pairs in the same order and of the same types | Show it »
!= | Inequality | $x != $y | Returns true if $x is not equal to $y | Show it »
<> | Inequality | $x <> $y | Returns true if $x is not equal to $y | Show it »
!== | Non-identity | $x !== $y | Returns true if $x is not identical to $y | Show it »

« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples